home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / trudf.zip / PAD.C < prev    next >
Text File  |  1993-01-04  |  2KB  |  59 lines

  1. /*********
  2. *
  3. * PAD.C
  4.  
  5. * Author   : Jean-Pierre van Melis, Helmond, The Netherlands
  6. * Compiled : with Microsoft C 5.1
  7. *   Object : can only be used in conjunction with Clipper summer '87
  8.  
  9. *  Syntax: PAD( <expC>, <expN> )
  10. *  Return: expC with a length of expN, padded with spaces
  11. *********/
  12.  
  13. #include "jplib.h"
  14.  
  15. CLIPPER pad()
  16.  
  17. {
  18.  
  19.    byte *par;                                   /* pointer to input */
  20.    byte *ret;                                   /* pointer to output */
  21.  
  22.    quant par_leng;                              /* length input */
  23.    quant ret_leng;                              /* length output */
  24.    quant i;                                     /* offset input */
  25.  
  26.    Boolean error =  TRUE;
  27.  
  28.    if(PCOUNT == 2 && ISCHAR(1) && ISNUM(2))
  29.    {
  30.       par      = _parc(1);                      /* receive pointer from clipper */
  31.       ret_leng = (quant) _parnd(2);             /* receive length from clipper */
  32.  
  33.       par_leng = (quant) _parclen(1);           /* get length of string */
  34.       par_leng = min(par_leng,ret_leng);
  35.  
  36.       ret      = _exmgrab(ret_leng+1);          /* Allocate memory */
  37.  
  38.       if(ret)                                   /* Enough memory available? */
  39.       {
  40.          error = FALSE;                         /* No errors */
  41.  
  42.          for(i = 0; i < par_leng; i++)          /* copy from input */
  43.             ret[i] = par[i];
  44.          while(i < ret_leng)                    /* fill rest with spaces */
  45.             ret[i++] = SPACEC;
  46.  
  47.          ret[i] = NULLC;                        /* terminate with null */
  48.       }
  49.    }
  50.    if(error)
  51.       _retc(NULLS);                             /* return null string */
  52.    else
  53.    {
  54.       _retclen(ret, ret_leng);                  /* return string with length */
  55.       _exmback(ret, ret_leng+1);                /* deallocate memory */
  56.    }
  57.    return;
  58. }
  59.